//
//  DCEvaluateTableViewCell.m
//  JiuyaoMotorcade
//
//  Created by 大橙子 on 2018/12/3.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCEvaluateTableViewCell.h"
CGFloat evaluateCellHeight = 130;
@interface DCEvaluateTableViewCell ()
@property (nonatomic,strong) UIView *firstView;
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UILabel *timeLabel;

@property (nonatomic,strong) UIView *secondView;
@property (nonatomic,strong) UILabel *evaluateLabel;

@property (nonatomic,strong) UIView *thirdView;
@property (nonatomic,strong) DCImageAndTextLabel *typeLabel;
@end
@implementation DCEvaluateTableViewCell
+(CGFloat)getCellHeight {
    return evaluateCellHeight;
}
+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *CellID = @"Cell";
    DCEvaluateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[DCEvaluateTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = BackgroundColor;
    }
    return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpMainUI];
    }
    return self;
}
-(void)setUpMainUI {
    self.firstView = [[UIView alloc]init];
    self.firstView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.firstView];
    
    self.nameLabel = [[UILabel alloc]init];
    [self.firstView addSubview:self.nameLabel];
    
    self.timeLabel = [[UILabel alloc]init];
    self.timeLabel.textAlignment = NSTextAlignmentRight;
    [self.firstView addSubview:self.timeLabel];
    
    self.secondView = [[UIView alloc]init];
    self.secondView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.secondView];
    
    self.evaluateLabel = [[UILabel alloc]init];
    self.evaluateLabel.numberOfLines = 0;
    [self.secondView addSubview:self.evaluateLabel];
    
    self.thirdView = [[UIView alloc]init];
    self.thirdView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.thirdView];
    self.typeLabel = [[DCImageAndTextLabel alloc]init];
    [self.thirdView addSubview:self.typeLabel];
}
-(void)layoutSubviews {
    [super layoutSubviews];
    self.firstView.frame = CGRectMake(0, 10, self.width, 35);
    self.nameLabel.frame = CGRectMake(15, 0, (self.firstView.width-25)/2, self.firstView.height);
    self.timeLabel.frame = CGRectMake(self.nameLabel.right, 0, self.nameLabel.width, self.nameLabel.height);

    CGSize size = [NSString sizeWithString:self.model.content fontSize:16 maxWidth:self.secondView.width-20 maxHeight:100];
    
    self.secondView.frame = CGRectMake(0, self.firstView.bottom+1, self.width, 100);
    
    self.evaluateLabel.frame = CGRectMake(10, 0, self.secondView.width-20, size.height);
    
    self.thirdView.frame = CGRectMake(0, self.secondView.bottom, self.width, 40);
    self.typeLabel.frame = CGRectMake(self.thirdView.width - 80*WIDTHSCALE6, 0, 80*WIDTHSCALE6, 40);
    
    evaluateCellHeight = 35+self.secondView.height+40+10;
}
-(void)setModel:(DCEvaluateModel *)model {
    _model = model;
    self.nameLabel.text = Str_IsEmpty(model.name)?@"匿名用户":model.name;
    self.timeLabel.text = Str_IsEmpty(model.time)?@"暂无":model.time;
    self.evaluateLabel.text = model.content;
    if ([self.model.type isEqualToString:@"好评"]) {
        self.typeLabel.imageView.image = IMAGENAME(@"好评");
        self.typeLabel.textLabel.text = @"好评";
    }else if ([self.model.type isEqualToString:@"中评"]) {
        self.typeLabel.imageView.image = IMAGENAME(@"中评");
        self.typeLabel.textLabel.text = @"中评";
    }else if ([self.model.type isEqualToString:@"差评"]) {
        self.typeLabel.imageView.image = IMAGENAME(@"差评");
        self.typeLabel.textLabel.text = @"差评";
    }
//    CGSize size = [NSString sizeWithString:self.model.content fontSize:16 maxWidth:self.width maxHeight:400];
//    evaluateCellHeight = 35+size.height+40+10;
    evaluateCellHeight = 35+100+40+10;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
